package tests;

import static org.junit.Assert.assertTrue;
import gestioneDatabase.Post.AllPostsRetriever;
import gestioneDatabase.Post.PostsManager;

import java.util.ArrayList;

import models.Post;
import models.User;

import org.junit.Before;
import org.junit.Test;


public class TestAllPostsRetriever {

	AllPostsRetriever testRetriever = null;
	ArrayList<Post> testPosts = null;
	ArrayList<Post> resultPosts = null;
	Post post = null;
	PostsManager testPostsManager = PostsManager.getManager();
	
	@Before
	public void createTestPostList(){
		post = new Post(new User("user1"));
		post.setTitle("title1");
		post.setContent("Contenuto di test");
		post.setStyle("capuccino");
	}
	
	@Test
	public void testConstructor() {
		testRetriever = new AllPostsRetriever();
	}

	@Test 
	public void testGetPosts(){
		boolean isIn = false;
		testPostsManager.insertPost(post.getAuthor(), post.getTitle(), post.getContent(), post.getStyle());
		testRetriever = new AllPostsRetriever();
		resultPosts = testPostsManager.getAllPostsList();
		testPosts = testRetriever.getPosts();
		for(Post post : resultPosts){
			if(post.getAuthor().getFullName().contains("user1") && post.getTitle().contains("title1") 
					&& post.getContent().contains("Contenuto di test") && post.getStyle().contains("capuccino"))
				isIn = true;	
		}
		assertTrue( testPosts.size() ==  resultPosts.size() && isIn);
	}
	
}
